package com.itheima.app.controller;

import com.itheima.app.mapper.UserLikeManager;
import com.itheima.vo.PageBeanVo;
import com.itheima.vo.UserLikeCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserLikeController {

    @Autowired
    private UserLikeManager userLikeManager;

    //喜欢
    @GetMapping("/tanhua/{id}/love")
    public void Love(@PathVariable("id") Long LikeUserId){
        userLikeManager.love(LikeUserId);
    }

    //不喜欢
    @GetMapping("/tanhua/{id}/unlove")
    public void unLove(@PathVariable("id") Long LikeUserId){
        userLikeManager.unlove(LikeUserId);
    }


    //喜欢统计
    @GetMapping("/users/counts")
    public UserLikeCountVo counts(){
        return userLikeManager.counts();
    }

    //喜欢详情
    @GetMapping("/users/friends/{type}")
    public PageBeanVo findType(
            @RequestParam(name = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pagesize", defaultValue = "10") Integer pageSize,
            @PathVariable Integer type) {
        return userLikeManager.findType(pageNum, pageSize, type);
    }


    //粉丝喜欢
    @PostMapping("/users/fans/{uid}")
    public void FansLove(@PathVariable("uid") Long likeUserId){
        userLikeManager.love(likeUserId);
    }

    //取消喜欢
    @DeleteMapping("/users/like/{uid}")
    public void unlike(@PathVariable("uid") Long likeUserId){
        userLikeManager.unlove(likeUserId);
    }
}
